package com.bungarus.group.auth;

import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;

public class HttpHeaderAuthTokenSecurityConfigurer
        extends AbstractHttpConfigurer<HttpHeaderAuthTokenSecurityConfigurer, HttpSecurity> {
    private final String key;
    private final AuthenticationManager authenticationManager;

    public HttpHeaderAuthTokenSecurityConfigurer(AuthenticationManager authenticationManager, final String key) {
        this.key = key;
        this.authenticationManager = authenticationManager;
    }

    @Override
    public void configure(HttpSecurity builder) throws Exception {
        builder.addFilterBefore(new HttpHeaderAuthTokenValidationFilter(authenticationManager, key), AnonymousAuthenticationFilter.class);
    }
}
